-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add jest-serializer module #5609
Conversation
packages/jest-serializer/README.md
Outdated
pipes. | ||
|
||
```javascript | ||
import serializer from 'jest-serializer'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructuring maybe?
import {serialize, deserialize} from 'jest-serializer';
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some Flow maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, pardon this is a test (so it's not necessary to flow it, but I like to mix these)
"license": "MIT", | ||
"main": "build/index.js", | ||
"dependencies": { | ||
"merge-stream": "^1.0.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is used this dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nowhere 😳I just copy-pasted the jest-worker
one and forgot to remove.
I like this but I have two high-level comments:
|
|
Let's remove the async ones until we need them. What I meant you can manually call |
: JSON.parse(fs.readFileSync(file, 'utf8')); | ||
} | ||
|
||
export function writeFileSync(file: Path, content: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you call this filePath
?
|
||
// Asynchronous filesystem functions. | ||
|
||
export function readFile(file: Path, callback: IOCallback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we expose an async API, I'd prefer it to be promise instead of callback based
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just killed the async one 😜. But you are right; it should have been Promise
based. I just followed the standard Node JS format.
The reason for killing it is because we don't really need it anywhere: neither in jest-haste-map
, nor in jest-worker
(coming soon), nor in Metro, where we will use this module as well.
Codecov Report
@@ Coverage Diff @@
## master #5609 +/- ##
==========================================
+ Coverage 60.63% 60.64% +<.01%
==========================================
Files 213 214 +1
Lines 7311 7310 -1
Branches 3 4 +1
==========================================
Hits 4433 4433
+ Misses 2877 2876 -1
Partials 1 1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
||
'use strict'; | ||
|
||
import prettyFormat from 'pretty-format'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty-format
should go to devDependencies now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually no 😅. There's no way you can develop jest
without having pretty-format
(yarn
complained when trying to add it, and it ended up adding it to the root package.json
instead of the child one).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I thought about this because it's going to be a standalone package, but then again, it's still inside a workspace monorepo. 👍
|
||
expect(buf).toBeInstanceOf(Buffer); | ||
|
||
expect(prettyFormat(serializer.deserialize(buf))).toEqual( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice workaround on different different contexts ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {[JS_TYPE]: 'm', [JS_VALUE]: Array.from(value)}; | ||
|
||
case Buffer: | ||
return {[JS_TYPE]: 'b', [JS_VALUE]: value.toString('latin1')}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason behind latin1
encoding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the most optimal way of converting a buffer into a string. Other candidates would be an array (way too long to decode), a UTF-8 string (but not all sequences you might find are valid sequences), or a hex one (which is going to longer or at most as equal as a latin1 string) 🙂
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR adds a new
jest-serializer
module, which combines V8 and JSON serializers, with APIs to serialize/deserialize in memory and/or from disk, either synchronously or asynchronously, which can later be used injest-haste-map
(as shown on the PR), or injest-worker
, to communicate between parent and child processes.Tests were added to it covering all APIs with a variety of objects.
Resolves #5575